const query = require('../db/query')

// 随机验证码
const getRanderCode = async (params) =>{
    let code = Math.random().toString().slice(2,6)
    await query(`TRUNCATE TABLE phone`)
    await query(`INSERT INTO phone (phone,phonecode) VALUES ('${params.phone}','${code}')`)
    return code
}

// 判断验证码是否正确
const checkCode = (params) =>{
    return query(`SELECT phonecode FROM phone WHERE phone = '${params.phone}' and phonecode = '${params.code}'`)
}

module.exports = {
    getRanderCode,
    checkCode
}